<script setup>
import ActivityNoteList from "@/views/contract/common/activityNote/activityNoteList.vue";
import {
  applySign, reAuditCon, signComplete
} from "@/api/contract/myContract.js";
import {pageofficeOpenFile} from "@/plugins/pageoffice/pageoffice-common.js";
import SelectUserList from "@/views/common/selectUserList.vue";
import {backMyConList} from "@/utils/backList.js";
import UploadFile from "@/views/common/uploadFile.vue";
import CancelButton from "@/views/contract/my/flowInfo/common/cancelButton.vue";
import {flowInfoFunctions, setCurrentIsRefreshActivityNote} from "@/utils/contract-my.js";

const {proxy} = getCurrentInstance()
const selectUserListRef = ref(null)
const loading = ref(false)
const prop = defineProps({
  conId: {
    type: Number
  },
  flowInfoButtons: {
    type: JSON
  },
  isRefreshActivityNote: {
    type: Boolean,
  }
})
const currentIsRefreshActivityNote = ref(prop.isRefreshActivityNote)
const conId = prop.conId
const {
  refreshMainViewData,
  handleApply,
  getApplyUserList,
  handleSelectedUser
} = flowInfoFunctions(prop, conId, applySign, loading, selectUserListRef, currentIsRefreshActivityNote)

//上传文件所需参数
const uploadFileRef = ref(null)
const uploadParams = ref({
  url: import.meta.env.VITE_APP_BASE_API + '/con/my/uploadSignFile',
  title: "上传对方盖章合同",
  accept: '.pdf',
  name: 'conFile',
  data: {id: conId}
})
function handleUpload() {
  uploadFileRef.value.openUploadDialog()
}

function openFile() {
  pageofficeOpenFile('/contract/my/sign/openFile/' + conId, conId)
}

function handleNext() {
  proxy.$modal.confirmAndExecuteJS('确认签订完毕，进入履行中？', signComplete, conId, refreshMainViewData)
}

function handleReAudit() {
  proxy.$modal.confirmAndExecuteJS('确认要重新审核当前合同，将其退回到审核中？', reAuditCon, conId, backMyConList)
}

</script>

<template>
  <el-row>
    <el-col :span="12" class="left">
      <el-row>
        <el-form-item>
          <el-button @click="backMyConList">返 回</el-button>
          <el-button type="primary" @click="openFile">打开正文</el-button>
          <el-button type="primary" @click="handleApply" v-if="flowInfoButtons.isApply">申请盖章</el-button>
          <el-button type="primary" @click="handleUpload" v-if="flowInfoButtons.isUploadSignFile">上传对方盖章合同</el-button>
          <el-button type="success" @click="handleNext" v-if="flowInfoButtons.isNext">签订完毕</el-button>
        </el-form-item>
      </el-row>
    </el-col>
    <el-col :span="12">
      <el-row justify="end">
        <el-form-item>
          <el-button type="primary" @click="handleReAudit" v-if="flowInfoButtons.isReAudit">重新审核</el-button>
          <CancelButton :conId="conId" :isCancel="flowInfoButtons.isCancel"/>
        </el-form-item>
      </el-row>
    </el-col>
  </el-row>
  <!-- 选择用户对话框 -->
  <SelectUserList ref="selectUserListRef" @getApplyUserList="getApplyUserList" @handleSelectedUser="handleSelectedUser"/>
  <!-- 上传对方盖章合同-->
  <UploadFile ref="uploadFileRef" :uploadParams="uploadParams"/>
  <!-- 流程信息列表 -->
  <ActivityNoteList :isRefreshActivityNote="currentIsRefreshActivityNote" :isCanAddActivityNote="true"/>
</template>

